package org.example.zzxsurprisemeal;


import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@SpringBootApplication
public class Application {

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}

@RestController
@RequestMapping("/api")
class ResultrantCollor {

    @GetMapping("/restaurants")
    public List<Resultrant> getRestaurants(@RequestParam(value = "location", required = false) String location) {
        List<Resultrant> restaurants = new ArrayList<>();
        restaurants.add(new Resultrant("惊喜餐厅", "市中心", "特色美食"));
        // 添加更多餐厅到列表中...

        // 如果查询参数 location 存在，则过滤餐厅列表
        if (location != null && !location.isEmpty()) {
            restaurants.removeIf(resultrant -> !resultrant.getLocation().equals(location));
        }

        return restaurants;
    }

    @PostMapping("/restaurants")
    public Resultrant createRestaurant(@RequestBody Resultrant resultrant) {
        // 这里可以添加逻辑来处理接收到的 Resultrant 对象
        // 例如，将其保存到数据库

        // 返回接收到的对象，或者根据需要返回其他内容
        return resultrant;
    }
}

class Resultrant {
    private String name;
    private String location;
    private String specialty;

    // 构造函数、getter 和 setter
    public Resultrant() {
    }

    public Resultrant(String name, String location, String specialty) {
        this.name = name;
        this.location = location;
        this.specialty = specialty;
    }

    // getter 和 setter 方法
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getLocation() {
        return location;
    }

    public void setLocation(String location) {
        this.location = location;
    }

    public String getSpecialty() {
        return specialty;
    }

    public void setSpecialty(String specialty) {
        this.specialty = specialty;
    }
}
